//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - Properties
//===================================================================================


namespace App.Domain.Handlers {
    using System;
    using App.Data;
    using App.Domain.Contracts;
    using App.Domain.Models;

    public class CreateTraining {
        private readonly ITrainingRepository _trainingRepository;

        public CreateTraining(ITrainingRepository trainingRepository) {
            _trainingRepository = trainingRepository;
        }

        public void Execute(Guid userId, ICreateTrainingCommand trainingForm) {
            if (trainingForm == null)
                throw new ArgumentNullException("trainingForm");

            try {
                var training = trainingForm.ConvertToEntity();
                _trainingRepository.Create(training);
            }
            catch (InvalidOperationException ex) {
                throw new BusinessServicesException("UnableToCreateVehicleExceptionMessage", ex);
            }
        }
    }
}
